home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 014 / amiga3d / startgfxdos.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  6KB  |  295 lines

  1. #define MAXPOINTS 64
  2.  
  3. #include <exec/types.h>
  4. #include <exec/nodes.h>
  5. #include <exec/lists.h>
  6. #include <graphics/gfx.h>
  7. #include <graphics/gfxbase.h>
  8. #include <graphics/clip.h>
  9. #include <graphics/rastport.h>
  10. #include <graphics/view.h>
  11. #include <graphics/text.h>
  12. #include <graphics/gfxmacros.h>
  13.  
  14. #include <graphics/layers.h>
  15. #include <intuition/intuition.h>
  16. #include <exec/memory.h>
  17. #include <exec/ports.h>
  18. #include <exec/libraries.h>
  19. #include <exec/interrupts.h>
  20. #include <graphics/copper.h>
  21. #include <hardware/dmabits.h>
  22. #include <hardware/custom.h>
  23. #include <graphics/gfxmacros.h>
  24.  
  25. #include <devices/timer.h>
  26.  
  27. #include "threed.h"
  28.  
  29. #define IS_PAL (((struct GfxBase *)GfxBase)->DisplayFlags & PAL)
  30.  
  31. long TimerBase;
  32. struct timerequest *timerio;
  33. extern struct Custom custom;
  34.  
  35. /* #define DEBUG */
  36. /* #define TICKDEBUG */
  37.  
  38. long GfxBase = 0;
  39. long LayersBase = 0;
  40. long IntuitionBase = 0;
  41. long DosBase = 0;
  42.  
  43. struct  AreaInfo areainfo;
  44. UWORD   areafill[(MAXPOINTS/2)*5];
  45.  
  46. int gettime()
  47. {
  48.     int ticks;
  49.     DoIO(timerio);
  50.     ticks = timerio->tr_time.tv_secs*60;
  51.     ticks += (timerio->tr_time.tv_micro*60)/1000000;
  52.     return(ticks);
  53. }
  54.  
  55. inittimer(usrproc,view,screen, window)
  56. int  (*usrproc)();
  57. struct View *view;
  58. struct Screen *screen;
  59. struct Window *window;
  60. {
  61.     int error = FALSE;
  62.  
  63.     /* allocate a timerequest structure */
  64.  
  65.     timerio = (APTR)AllocMem(sizeof(struct timerequest),MEMF_CLEAR);
  66.  
  67.     /* open the timer device */
  68.  
  69.     TimerBase = OpenDevice("timer.device",UNIT_VBLANK,timerio,0);
  70.  
  71.     /* initialize stuff to read timer value back */
  72.  
  73.     timerio->tr_node.io_Command = TR_GETSYSTIME;
  74.  
  75.     error = (*usrproc)(view,screen,window);
  76.  
  77.     /* close timer device */
  78.  
  79.     CloseDevice(timerio);
  80.  
  81.     /* clean up */
  82.  
  83.     FreeMem(timerio,sizeof(struct timerequest));
  84.  
  85.     return(error);
  86. }
  87.  
  88. timeproc(usrproc,view,screen, window)
  89. int  (*usrproc)();
  90. struct View *view;
  91. struct Screen *screen;
  92. struct Window *window;
  93. {
  94.     int error = FALSE;
  95.     int starttime;
  96.  
  97.     starttime = gettime();
  98.  
  99.     error = (*usrproc)(view,screen,window);
  100.  
  101.     if (!error)
  102.     {
  103.         return(gettime() - starttime);
  104.     }
  105.     else 
  106.     {
  107.         return(error);
  108.     }
  109.  
  110. }
  111.  
  112. startgfxdos(x,y,height,width,n_bit_planes,usrproc,s,flags,tmpras,sbitmap)
  113. WORD x,y;
  114. UWORD height, width, n_bit_planes;
  115. int (*usrproc)();
  116. UBYTE *s;
  117. ULONG flags;
  118. struct TmpRas *tmpras;
  119. struct BitMap *sbitmap;
  120. {
  121.     struct Screen *screen;
  122.     struct Window *window;
  123.     struct RastPort *w;
  124.     struct View *view;
  125.     short idcmp;
  126.     struct NewWindow nw;
  127.     struct NewScreen ns;
  128.         int error = FALSE;
  129.  
  130. #ifdef DEBUG
  131.     printf("startgfxdos: opening graphics lib...\n");
  132. #endif
  133.     
  134.     if ( (!GfxBase) && ( (GfxBase = OpenLibrary("graphics.library",0) ) == NULL) )
  135.     {
  136. #ifdef DEBUG
  137.         printf("startgfxdos: can't open graphics lib...\n");
  138. #endif
  139.         return((int)-1);
  140.     }
  141.  
  142. #ifdef DEBUG
  143.     printf("startgfxdos: opening layers lib...\n");
  144. #endif
  145.     
  146.     if ( (LayersBase = OpenLibrary("layers.library",0)) == NULL)
  147.     {
  148. #ifdef DEBUG
  149.         printf("startgfxdos: can't open layers lib...\n");
  150. #endif
  151.         return((int)-1);
  152.     }
  153.  
  154. #ifdef DEBUG
  155.     printf("startgfxdos: opening intuition lib...\n");
  156. #endif
  157.  
  158.     if ( (IntuitionBase = OpenLibrary("intuition.library",0)) == NULL)
  159.     {
  160. #ifdef DEBUG
  161.         printf("startgfxdos: can't open intuition lib...\n");
  162. #endif
  163.         return((int)-1);
  164.     }
  165.  
  166.     ns.LeftEdge = x;
  167.     ns.TopEdge = 0;
  168.     ns.Width = width;
  169.     ns.Height = ((height>(IS_PAL?PAL_MAXHINOLACE:NTSC_MAXHINOLACE))?(IS_PAL?PAL_MAXHILACE:NTSC_MAXHILACE):(IS_PAL?PAL_MAXHINOLACE:NTSC_MAXHINOLACE));
  170.     ns.Depth = n_bit_planes;
  171.     ns.DetailPen = -1;
  172.     ns.BlockPen = -1;
  173.     ns.ViewModes = ( 0 | ((width > 320)?HIRES:0) | ((height>(IS_PAL?PAL_MAXHINOLACE:NTSC_MAXHINOLACE))?LACE:0) );
  174.     ns.Type = CUSTOMSCREEN;
  175.     ns.Font = NULL;
  176.     ns.DefaultTitle = NULL;
  177.     ns.Gadgets = NULL;
  178.  
  179. #ifdef DEBUG
  180.     printf("startgfxdos: opening a custom screen...\n");
  181. #endif
  182.  
  183.     if ( (screen = (struct Screen *)OpenScreen(&ns)) == NULL)
  184.     {
  185. #ifdef DEBUG
  186.         printf("startgfxdos: can't open a custom screen...\n");
  187. #endif
  188.         return((int)-1);
  189.     }
  190.  
  191.         screen->ViewPort.DxOffset = x;
  192.  
  193. #ifdef DEBUG
  194.     printf("startgfxdos: calling makescreen, rethinkdisplay...\n");
  195. #endif
  196.  
  197.     MakeScreen(screen);
  198.     RethinkDisplay();
  199.  
  200.     ShowTitle(screen,FALSE); /* let backdrop window title bars show */
  201.  
  202.     idcmp = CLOSEWINDOW;
  203.  
  204.     nw.LeftEdge = 0;
  205.     nw.TopEdge = y;
  206.     nw.Width = width;
  207.     nw.Height = height;
  208.     nw.DetailPen = -1;
  209.     nw.BlockPen = -1;
  210.     nw.IDCMPFlags = idcmp;
  211.     nw.Flags = WINDOWCLOSE|flags;
  212.     nw.FirstGadget = NULL;
  213.     nw.CheckMark = NULL;
  214.     nw.Title = s;
  215.     nw.Screen = screen;
  216.     nw.BitMap = sbitmap;
  217.     nw.MinWidth = width;
  218.     nw.MinHeight = height;
  219.     nw.MaxWidth = width;
  220.     nw.MaxHeight = height;
  221.     nw.Type = CUSTOMSCREEN;
  222.  
  223. #ifdef DEBUG
  224.     printf("startgfxdos: opening a window in the custom screen...\n");
  225. #endif
  226.  
  227.     if ( (window = (struct Window *)OpenWindow(&nw)) == NULL )
  228.     {
  229. #ifdef DEBUG
  230.         printf("startgfxdos: can't open a new window...\n");
  231. #endif
  232.         return((int)-1);
  233.     }
  234.  
  235.     if(window->RPort)
  236.     {
  237. #ifdef DEBUG
  238.         printf("startgfxdos: initialize and link areainfo to this window's rastport...\n");
  239. #endif
  240.         InitArea(&areainfo,areafill,MAXPOINTS);
  241.         window->RPort->AreaInfo = &areainfo;
  242.     }
  243.     else
  244.     {
  245. #ifdef DEBUG
  246.         printf("startgfxdos: null window rastport pointer...\n");
  247. #endif
  248.         return((int)-1);
  249.     }
  250.  
  251. #ifdef DEBUG
  252.     printf("startgfxdos: trying to find the view adress...\n");
  253. #endif
  254.  
  255.     if ( (view = (struct View *)ViewAddress()) == NULL) 
  256.     {
  257. #ifdef DEBUG
  258.         printf("startgfxdos: can't get view address...\n");
  259. #endif
  260.         return((int)-1);
  261.     }
  262.  
  263.     window->RPort->TmpRas = tmpras;
  264.  
  265. #ifdef DEBUG
  266.     printf("startgfxdos: calling the usrproc routine ...\n");
  267. #endif
  268.  
  269. #ifdef TICKDEBUG
  270.  
  271. #ifdef DEBUG
  272.     printf("though the inittimer routine ...\n");
  273. #endif
  274.     error = inittimer(usrproc,view,window->WScreen,window);
  275. #else
  276.     error = (*usrproc)(view,window->WScreen,window);
  277. #endif
  278.  
  279. #ifdef DEBUG
  280.     printf("startgfxdos: returnted from the usrproc with error = %lx...\n",error);
  281. #endif
  282.  
  283. #ifdef DEBUG
  284.     printf("startgfxdos: close the window...\n");
  285. #endif
  286.     CloseWindow(window);     
  287.  
  288. #ifdef DEBUG
  289.     printf("startgfxdos: close the screen...\n");
  290. #endif
  291.     CloseScreen(screen);
  292.  
  293.     return(error);
  294. }
  295.